package com.example.edu.Mapper;

import com.example.edu.Entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TagMapper {
    List<Tag> selectExist(@Param("tags") List<Tag> tags);
    void insertMany(@Param("tags") List<Tag> tags);

    @Select("select tag_id,tag_name from tag_doc_tag where document_id = #{document_id}")
    List<Tag> getTagByDoc(@Param("document_id") int document_id);

    @Select("select tag_name from tag_doc_tag where document_id = #{document_id}")
    List<String> getTagNamesByDoc(@Param("document_id") int document_id);

    @Select("select tag_id,tag_name from doc_tag_doc_tag where document_course = #{course_id} and document_chapter = #{chapter_id} order by tag_id")
    List<Tag> getTags(@Param("course_id") int course_id, @Param("chapter_id") int chapter_id);

    @Select("select tag_id,tag_name from doc_tag_doc_tag where document_course = #{course_id} and document_chapter = #{chapter_id} and (`right` = 0 or document_user = #{user_id}) order by tag_id")
    List<Tag> getTagsS(@Param("course_id") int courseId, @Param("chapter_id") int chapterId, @Param("user_id") int userId);

    @Select("select t.tag_id,t.tag_name from tag t left join tag_doc td on t.tag_id = td.tag_id where td.document_id is null")
    List<Tag> getWildTag();

    void deleteByIds(@Param("tag_ids") List<Integer> tag_ids);

}
